package com.example.design.iterator;


import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

//迭代器模式具体容器角色
@Data
@JsonIgnoreProperties
@NoArgsConstructor
@AllArgsConstructor
public class EsSqlQuery implements EsSqlQueryInterface<EsQueryIterator>{

    //查询语句
    private String query;
    //每次查询返回的记录数
    private Long fetchSize;
    //分页参数游标
    private String cursor;

    //第一次查询只传入query,fetchSize
    @JsonCreator
    public EsSqlQuery(@JsonProperty("query") String query,@JsonProperty("fetchSize") Long fetchSize) {
        this.query = query;
        this.fetchSize = fetchSize;
    }

    public EsSqlQuery(String cursor) {
        this.cursor = cursor;
    }

    //创建具体迭代器
    @Override
    public EsQueryIterator iterator() {
        return new EsQueryIterator(this.query,this.fetchSize);
    }
}
